package 二叉树题目.二叉树的后序遍历;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public int[] postorderTraversal (TreeNode root) {
        // write code here
        List<Integer> list = new ArrayList<>();
        postorder(root,list);
        int[] ret = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            ret[i] = list.get(i);
        }
        return ret;
    }

    public void postorder(TreeNode root, List<Integer> list){
        if (root == null){
            return;
        }
        postorder(root.left,list);
        postorder(root.right,list);
        list.add(root.val);
    }
}
